package com.leaderment.timatt.webmagic.listener;

import com.leaderment.timatt.webmagic.pageprocessor.MyPageProcessor;


public class MyPageProcessorListener{
	//关键词完成
	public void finished(MyPageProcessor pageProcessor) {/*
		try {
			//完成后移除阻塞队列的个数
			//pageProcessor.amazonKeywordRankingTask.threadBlockQueue.take();
			
			//完成后手动将对应的spider停止
			Spider spider=pageProcessor.amazonKeywordRankingTask.spiderMap.get(pageProcessor.keyword.toString());
			spider.close();
			Thread.sleep(5000);
			spider.stop();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	
		//InitHandler.log.info("线程："+pageProcessor.keyword.getAdvertisingKeywordId()+"停止成功");
		InitHandler.log.warn(
				"关键词已执行总数为:"+pageProcessor.amazonKeywordRankingTask.allCount.incrementAndGet()+"完成关键词为："+pageProcessor.keyword.getKeywordString());*/
	}
	//关键词未完成
	public void unFinished(MyPageProcessor pageProcessor) {
		//1.失败后将对应的spider停止
		/*Spider spider=pageProcessor.amazonKeywordRankingByCountry.spiderMap.get(pageProcessor.keyword.getAdvertisingKeywordId());
		spider.stop();
		//2.失败的关键词重新放回队列
		synchronized (pageProcessor.amazonKeywordRankingByCountry.countryKeywordList) {
			pageProcessor.amazonKeywordRankingByCountry.countryKeywordList.offer(pageProcessor.keyword);
		}
		//完成后移除阻塞队列的个数
		try {
			pageProcessor.amazonKeywordRankingTask.threadBlockQueue.take();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		InitHandler.log.info(
				"关键词已执行总数为:"+pageProcessor.amazonKeywordRankingTask.allCount.get());*/
		
	}
	

}
